function loadJsFileByEval(moduleName, callback){
	Ext.Ajax.request({
		url: convertClazzName2FilePath(moduleName),
		success: function(response){
			var o = eval(response.responseText);//动态执行js文件，o为返回值
			callback();
		},
		failure: function() {
		}
	});

	function convertClazzName2FilePath(componentName){
		var pattern = new RegExp("\\.", 'g');
		var filePath = componentName.replace(pattern, "/");
		var pattern2 = new RegExp("Mind/", 'g');
		var filePath2 = componentName.replace(pattern2, "/");
		filePath2 = ctx + "/resources/js" + filePath + ".js";
		return filePath2;
	}
}

ModuleMap = new Object();
function registerModule(moduleName, moduleReference){
	ModuleMap[moduleName] = moduleReference;
}

function getModule(moduleName){
	return ModuleMap[moduleName];
}

function objArrayUnique(array, attr){
	var idArray = [];
	var objArray = [];
	$.map(array, function(v){
		if($.inArray(v[attr], idArray)==-1){
			idArray.push(v[attr]);
			objArray.push(v);
		}
	});
	return objArray;
}

function enumMap2ObjArray(enumMap){
	var arr = [];
	$.each(enumMap, function( n, v){
		arr.push([n, v]);
	});
	return new Ext.data.ArrayStore({
		data : arr,
		fields : ["value", "display"]
	});
}



/**
 * js文件里引入js css
 * @param {} path	文件路径
 * @param {} type	文件类型
 */
function importFile(path, type){
    var scripts = document.getElementsByTagName("script");
    var cssLinks = document.getElementsByTagName("link");
    var ctx = "/mind/";
    if(type=="css"){
        for (i = 0; i < cssLinks.length; i++) {
            if(cssLinks[i].href.match(path)){
                return;
            }
        }
        document.write("<" + "link href=\"" + ctx  + path + ".css\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
    }else if(type=="js"){
        for (i = 0; i < scripts.length; i++) {
            if(scripts[i].src.match(path)){
                return;
            }
        }
        document.write("<" + "script src=\"" + ctx + path + ".js\"></" + "script>");
    }
}



function convertClazzName2FilePath(componentName){
    var pattern = new RegExp("\\.", 'g');
    var filePath = componentName.replace(pattern, "/");
    filePath = "/TR/js/" + filePath + ".js";
    return filePath;
}

/**
 * 同步ajax请求
 * 
 * @param {}
 *            url地址
 * @return {}
 */
function synchronizeAjaxRequest(url,paras){
	var xmlhttp=null;
	if (window.XMLHttpRequest){// code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	
	
	if (xmlhttp != null && url) {		
		xmlhttp.open("GET", url.toString(), false);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); 
		xmlhttp.send(paras);
		if (xmlhttp.responseText != '') {
			return xmlhttp.responseText;
		} else {
			alert('服务器出现错误请稍后再试！');
		}
	} else {
		alert('创建HTTP请求失败！');
	}
};   

/**
 *同步ajax请求 decode
 * @param {} url地址
 * @return {}
 */
function syncAjaxReqDecode(url,paras){
	var xmlhttp=null;
	if (window.XMLHttpRequest){// code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	

	if (xmlhttp != null) {
		xmlhttp.open("POST", url, false);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); 
		xmlhttp.send(paras);
		if (xmlhttp.responseText != '') {
			var xmlhttpData = Ext.util.JSON.decode(xmlhttp.responseText);
			if(xmlhttpData){
//				if(checkUserSessionStatus(xmlhttpData))return '';//是否超时
				if(ajaxRequestResult(xmlhttpData) == false)return '';//操作是否成功
			}
			return xmlhttpData;
		} else {
			alert('服务器出现错误请稍后再试！');
		}
	} else {
		alert('创建HTTP请求失败！');
	}
};   
/**
 * 同步请求session检查
 * @param {} data
 * @return {Boolean}
 */
function syncAjaxReqSessionCheck(data){
	if(data.sessionstatus == 'timeout'){   
		askMesg({title:'确认', 
				 msg:'对不起,会话失效.请重新登录.', 
				 fn:function(confirm){
							if('ok' == confirm)
                             	reLogin();
                    }
		});   
       return false;
	} 
}

/**
 * 加载XML文件 
 * xmlFile	xml文件路径
 *  */
function loadXMLFile(xmlFile) {
	var xmlDoc;
	try{
		if (window.ActiveXObject) {
			xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
		} else {
			if (document.implementation && document.implementation.createDocument) {
				xmlDoc = document.implementation.createDocument("text/xml", "",
						null);
			} else {
				return null;
			}
		}
		xmlDoc.async = false;		
		xmlDoc.load(xmlFile);
	}catch(e){
		try{//Google Chrome   
		   var xmlhttp = new window.XMLHttpRequest();   
		   xmlhttp.open("GET",xmlFile,false);   
		   xmlhttp.send(null);   
		   xmlDoc = xmlhttp.responseXML.documentElement;   
	  	}catch(e){   
	   	   alert(e.message);   
	  	}  
	}
	return xmlDoc;
}

/**
 * 获得描述域字符串
 * @param {} moduleId
 * @param {} xmlDoc
 */
function getFieldNamesJson(moduleId,xmlDoc){
    var resultJson = '"moduleId":"'+moduleId+'"';
	var nodes = xmlDoc.getElementsByTagName("field");
	for(var i=0;i<nodes.length;i++){
		var fieldName = nodes[i].getAttribute('name');
		var fieldValue = '';
		if(Ext.isIE){
			fieldValue = nodes[i].nodeTypedValue;
		}else{
			fieldValue = nodes[i].textContent;
		}
		resultJson = resultJson +',"'+fieldName+'":"'+ fieldValue +'"';
	}
	resultJson = '{'+resultJson+'}';
	return resultJson;
}

/**
 * 通过XML文件动态加载模块的js
 * @param {} xmlDoc		文档对象
 * @param {} viewType	页面视图类型
 */
function dynamicLoadModuleJs(xmlDoc,viewType,moduleId){	
	var jsUrlShareChildNodes = xmlDoc.getElementsByTagName('jsUrlShare');
	for(var i=0;i<jsUrlShareChildNodes.length;i++){
		if(jsUrlShareChildNodes[i].parentNode.nodeName == viewType){
			var jsUrlShare = jsUrlShareChildNodes[i].childNodes[0].nodeValue;
			if(basicConstant.DYNAMIC_LOAD_JS_MAP.get(jsUrlShare) == undefined){
				var responseText = synchronizeAjaxRequest(jsUrlShare);
				eval(responseText);
				basicConstant.DYNAMIC_LOAD_JS_MAP.put(jsUrlShare,jsUrlShare);
			}
		}
	}
	
	var jsUrlChildNodes = xmlDoc.getElementsByTagName('jsUrl');
	for(var i=0;i<jsUrlChildNodes.length;i++){
		if(jsUrlChildNodes[i].parentNode.nodeName == viewType){
			var jsUrl = jsUrlChildNodes[i].childNodes[0].nodeValue;
			var responseText = synchronizeAjaxRequest(jsUrl);
			eval(responseText);
		}
	}
	
	var resultJson = getFieldNamesJson(moduleId,xmlDoc);
	var mainClassChildNodes = xmlDoc.getElementsByTagName('jsMainClassName');
	var jsMainClassInstance = null;
	for(var i=0;i<mainClassChildNodes.length;i++){
		if(mainClassChildNodes[i].parentNode.nodeName == viewType){
			var jsMainClassName = mainClassChildNodes[i].childNodes[0].nodeValue;
			jsMainClassInstance = 'new ' + jsMainClassName + '('+resultJson+')';
			break;
		}
	}
	basicConstant.DYNAMIC_JS_INSTANCE_MAP.put(moduleId+'_'+viewType,jsMainClassInstance);
}

/**
 *关闭窗口时销毁session
 */
function sessionInvalidate(){
//	sessionManger.sessionDestroyed();
}